<template>
  <div class="container">
    <leftcont></leftcont>
    <div class="righCont">
      <topcont></topcont>
      <div class="content">
        <div class="payTable">
          <div class="trendTop">所有用户({{ total }})</div>
          <div class="tableCont">
            <div class="tableSerchCont">
              <div class="serchItem" style="width: 250px">
                <el-input
                  v-model="serchVal"
                  placeholder="请输入用户昵称|或编号"
                ></el-input>
              </div>
              <div class="headBtn">
                <btn value="搜索" @click="serchFn"></btn>
              </div>
            </div>
            <el-table :data="tableData" style="width: 100%">
              <el-table-column
                prop="nick_name"
                show-overflow-tooltip
                label="用户昵称"
              >
              </el-table-column>
              <el-table-column show-overflow-tooltip label="用户头像">
                <template #default="scope">
                  <img class="userImg" :src="scope.row.head_img" />
                </template>
              </el-table-column>
              <el-table-column prop="user_number" label="用户编号">
              </el-table-column>
              <el-table-column prop="consumption_money" label="消费金额">
              </el-table-column>
              <el-table-column prop="create_time" label="加入时间">
              </el-table-column>
            </el-table>
            <div class="pageCont">
              <el-pagination
                background
                layout="prev, pager, next"
                :page-size="per_page"
                :current-page="page"
                @current-change="pageFn"
                :total="total"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import leftcont from "@/components/leftCont.vue";
import topcont from "@/components/topCont.vue";
import btn from "@/components/public/btn.vue";
import { allUser } from "@/http/api";

export default {
  components: { leftcont, topcont, btn },
  data() {
    return {
      serchVal: "",
      tableData: [],
      page: 1,
      per_page: 5,
      total: 0,
    };
  },
  props: {},
  methods: {
    pageFn(index) {
      this.page = index;
      this.getdata();
    },
    serchFn() {
      this.page = 1;
      this.total = 0;
      this.getdata();
    },
    getdata() {
      var data = {
        search: this.serchVal,
        page: this.page,
        per_page: this.per_page,
      };
      allUser(data)
        .then((res) => {
          if (res.data.code == 1) {
            this.tableData = res.data.data.data; //把最新的数组赋值给tableData
            this.total = res.data.data.total;
          } else {
            ElMessage(res.data.msg);
          }
        })
        .catch((err) => {
          ElMessage.error("服务器请求超时");
        });
    },
  },
  mounted() {},
  created() {
    this.getdata();
  },
};
</script>

<style scoped lang="less">
.container {
  width: 100%;
  display: flex;
  height: 100vh;
  overflow: hidden;
  .righCont {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-left: 15px;
    height: 100%;
    width: 10px;
    background-color: #f4f8ff;
    .content {
      padding: 20px;
      box-sizing: border-box;
      width: 100%;
      flex: 1;
      .payTable {
        width: 100%;
        height: 100%;
        background-color: #fff;
        padding: 15px;
        border-radius: 5px;
        overflow: auto;
        box-sizing: border-box;
        .trendTop {
          font-weight: bold;
          font-size: 16px;
          cursor: pointer;
        }
        .tableCont {
          width: 100%;
          margin-top: 15px;
          .userImg {
            height: 40px;
            border-radius: 5px;
          }
          .redBtn {
            color: #f56c6c;
          }
          .blueBtn {
            color: #96a1fe;
          }
          .greenBtn {
            color: #85ce61;
          }
          .blackBtn {
            color: #666;
          }
          .tableSerchCont {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            margin-bottom: 10px;
            .serchItem {
              width: 150px;
              margin-left: 10px;
            }
            .headBtn {
              margin-left: 10px;
            }
          }
          .ctrolBtn {
            display: flex;
            .text_btn {
              margin: 0 5px;
              cursor: pointer;
              font-size: 14px;
            }
          }
          .pageCont {
            padding: 30px 0;
            display: flex;
            justify-content: center;
          }
        }
      }
    }
  }
}
</style>
